#!/usr/bin/python
# -*- coding: cp1250 -*-

import time
import datetime

def byDateTime(in_s, shiftMinutes):
    if in_s == '':
        return ""
    else:
        if len(in_s) == 5:
            in2_s = '2000-01-01 '+in_s+':00'
        else:
            in2_s = in_s

        inDate =    datetime.datetime(*time.strptime(in2_s, "%Y-%m-%d %H:%M:%S")[0:5]) \
                    + datetime.timedelta(minutes=shiftMinutes) 
        # the '*' operator unpacks the tuple, producing the argument list.
        if len(in_s) == 5:
            return      inDate.strftime("%Y-%m-%d %H:%M:%S").lstrip("0")[11:16]
        else:
            return      inDate.strftime("%Y-%m-%d %H:%M:%S").lstrip("0")

def byDate(in_s, shiftDays):
    ''' return shifted (by days) date
    import pepe.datetimex.shift as pds
    pds.byDate('2007-05-11',1)
    '''
    inDate =    datetime.datetime(*time.strptime(in_s, "%Y-%m-%d")[0:5]) \
                + datetime.timedelta(days=shiftDays) 
    # the '*' operator unpacks the tuple, producing the argument list.
    return      inDate.strftime("%Y-%m-%d").lstrip("0")

def main():
    print """\nbyDateTime("2007-03-04 00:03:00",-6)""",
    print byDateTime("2007-03-04 00:03:00",-6)
    print """byDateTime("2007-03-04 23:59:00",6)""",
    print byDateTime("2007-03-04 23:59:00",6)
    print """byDateTime("00:03",-6)""",
    print byDateTime("00:03",-6)
    print """byDateTime("23:59", 6)""",
    print byDateTime("23:59", 6)
    print byDateTime("", 6)

    print byDate('2007-05-11', -1)
    print byDate('2007-05-11', -255)
    
if __name__ == "__main__":
    main()
